package com.guaju.yueshangLife.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.activity.CaculateActivity;
import com.guaju.yueshangLife.activity.OrderGoodsListActivity;
import com.guaju.yueshangLife.bean.CartGoods;
import com.guaju.yueshangLife.bean.CouponsBean;
import com.guaju.yueshangLife.bean.PrepareOrderBean;
import com.guaju.yueshangLife.recyclerView.BaseRecyclerAdapter;
import com.guaju.yueshangLife.recyclerView.BaseRecyclerHolder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class CaculateGoodsAdapter extends BaseRecyclerAdapter<CartGoods> {
    String delivery;
    List<PrepareOrderBean.DataBean.CouponsBean> couponsBeans;

    public void setDelivery(String delivery) {
        this.delivery = delivery;
    }

    public CaculateGoodsAdapter(Context context) {
        super(context, R.layout.item_caculate_goods);
    }

    public String getDelivery() {
        return delivery;
    }

    public List<PrepareOrderBean.DataBean.CouponsBean> getCouponsBeans() {
        return couponsBeans;
    }

    public void setCouponsBeans(List<PrepareOrderBean.DataBean.CouponsBean> couponsBeans) {
        this.couponsBeans = couponsBeans;
    }

    @Override
    public void convert(BaseRecyclerHolder holder, CartGoods item, int position) {
        SimpleDraweeView pic = holder.getView(R.id.pic);
        final CartGoods cartGoods = getDatas().get(position);
        String color = cartGoods.getColor();
        pic.setImageURI(cartGoods.getImageUrl());
        int count = cartGoods.getCount();
        String size = cartGoods.getSize();
        String price = cartGoods.getPrice();
        String buyinfo=color+"; "+size+"; "+count+"件;";
        holder.setText(R.id.buy_info,buyinfo);
        holder.setText(R.id.price,"¥"+price);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, OrderGoodsListActivity.class);
                Bundle bundle = new Bundle();
                List<CartGoods> datas = getDatas();
                bundle.putString("delivery",delivery);
                bundle.putSerializable("goods", (Serializable) datas);
                if (couponsBeans!=null&&!couponsBeans.isEmpty()){
                bundle.putSerializable("coupons", (Serializable) couponsBeans);
                }
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }
}
